package com.douqu.game.main;


import com.douqu.game.core.config.AssetConfig;
import com.douqu.game.core.config.card.CardConfig;
import com.douqu.game.core.config.common.GoodsData;
import com.douqu.game.core.config.goods.PropConfig;
import com.douqu.game.core.controller.PlayerController;
import com.douqu.game.core.e.E_MailSenderType;
import com.douqu.game.core.entity.Player;
import com.douqu.game.core.entity.ext.BagInfo;
import com.douqu.game.core.entity.ext.ChallengeInfo;
import com.douqu.game.core.entity.ext.MailInfo;
import com.douqu.game.core.entity.ext.TaskInfo;
import com.douqu.game.core.factory.ConstantFactory;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.factory.LoadFactory;
import com.douqu.game.core.protobuf.SGCommonProto;
import com.douqu.game.core.util.LogUtils;
import com.douqu.game.main.gui.MainFrame;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: Bean
 * @Description:
 * @Date: 2017-11-21 15:52
 */
public class StartServer {

    public static void main(String[] args)
    {
        if (args.length > 0)
        {
            LoadFactory.FIXED_CONFIG_PATH = args[0];
        }
        if (args.length > 1)
        {
            LoadFactory.DYNAMIC_CONFIG_PATH = args[1];
        }

        LogUtils.warn("FIXED_CONFIG_PATH ========> ", LoadFactory.FIXED_CONFIG_PATH);
        LogUtils.warn("DYNAMIC_CONFIG_PATH ==========> ", LoadFactory.DYNAMIC_CONFIG_PATH);

        SpringServer.args = args;

        MainFrame mainFrame = new MainFrame();
        GameServer.getInstance().setMainFrame(mainFrame);

        mainFrame.init();
        mainFrame.showFrame();
    }


    public static void testAllPlayer()
    {
        int i = 0;
        Player player = null;
        PlayerController playerController = null;
        while(++i < 1000)
        {
            player = createRichPlayer("i_" + i);
            playerController = new PlayerController(player, null);
            GameServer.getInstance().getWorldManager().playerEnterGame(playerController);
        }
    }

    public static Player createRichPlayer(String objectIndex)
    {
        Player player = new Player();
        player.objectIndex = objectIndex;
        player.init();

        BagInfo bagInfo = player.getExtInfo(BagInfo.class);
        List<CardConfig> cardConfigs = DataFactory.getInstance().getDataList(DataFactory.CARD_KEY);
        List<AssetConfig> assetConfigs = DataFactory.getInstance().getDataList(DataFactory.ASSET_KEY);
        List<PropConfig> propConfigs = DataFactory.getInstance().getDataList(DataFactory.PROP_KEY);

        List<GoodsData> goodsDataList = new ArrayList<>();
        for (CardConfig cardConfig : cardConfigs) {
            goodsDataList
                    .add(new GoodsData(SGCommonProto.E_GOODS_TYPE.GOODS_TYPE_CARDS_VALUE, cardConfig.id, 10));
        }
        for (AssetConfig assetConfig : assetConfigs) {
            goodsDataList.add(new GoodsData(SGCommonProto.E_GOODS_TYPE.GOODS_TYPE_ASSETS_VALUE, assetConfig.id,
                    10000000));
        }
        for (PropConfig propConfig : propConfigs) {
            if (propConfig.type == ConstantFactory.PROP_TYPE_TIME_PROP)
                continue;

            goodsDataList.add(
                    new GoodsData(SGCommonProto.E_GOODS_TYPE.GOODS_TYPE_PROPS_VALUE, propConfig.id, 10000000));
        }
        GoodsData[] goodsDatas = new GoodsData[goodsDataList.size()];
        for (int i = 0; i < goodsDataList.size(); i++) {
            goodsDatas[i] = goodsDataList.get(i);
        }
        bagInfo.addGoods(goodsDatas, null);

        MailInfo mailInfo = player.getExtInfo(MailInfo.class);
        int i = 0;
        while(++i < 30)
            mailInfo.addMail(SGCommonProto.E_MAIL_TYPE.MAIL_TYPE_SYSTEM_VALUE,"测试邮件", "测试邮件", E_MailSenderType.MAIL_TYPE_RECEIVER.getCode(),objectIndex,null,System.currentTimeMillis());

        ChallengeInfo challengeInfo = player.getExtInfo(ChallengeInfo.class);
        i = 0;
        while(++i < 50)
            challengeInfo.getInstanceData().addPassLevel(1, 1, i, 1);

        TaskInfo taskInfo = player.getExtInfo(TaskInfo.class);
        taskInfo.finishAllMainTask();

        return player;
    }
}
